<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>自定义JS对象</title>
    </head>
    <body>
        <table border="1">
            <caption>商品表</caption>
            <tr>
                <th>商品标题</th>
                <th>商品价格</th>
                <th>商品库存</th>
            </tr>
        </table>
        <script>
            let products = [
                {title:'凯迪拉克CT6', price:500000, num:100},
                {title:'红旗国雅', price:1800000, num:200},
                {title:'梅赛德斯E300', price:700000, num:300},
                {title:'奥迪霍希', price:2000000, num:400},
                {title:'保时捷卡宴', price:1600000, num:500},
                {title:'法拉利488', price:2500000, num:600},
                {title:'兰博基尼Veneno', price:3000000, num:700},
                {title:'劳斯莱斯库里南', price:3000000, num:800},
                {title:'布加迪威龙', price:8000000, num:900}
            ];
            function tj() {
                let tableE = document.querySelector('table');
                for (let i = 0; i < products.length; i++) {
                    let tr = document.createElement('tr');
                    let titleTd = document.createElement('td');
                    let priceTd = document.createElement('td');
                    let numTd = document.createElement('td');

                    titleTd.innerHTML = products[i].title;
                    priceTd.innerHTML = products[i].price;
                    numTd.innerHTML = products[i].num;
                    tr.append(titleTd, priceTd, numTd);
                    tableE.append(tr);
                }
            }
            tj();
            //1.定义一个js对象
            let p1 = {
                name:'张三',
                age:18,
                say:function(){
                    return '我是'+this.name+',今年'+this.age+'岁';
                }
            }
            p1.say();
            console.log(p1.name, p1.age);
            console.log(p1);
            //2.先定义一个空对象，再动态向其添加属性与方法
            let p2 = {};
            p2.name = '李四';
            p2.age = 20;
            p2.say = function(){
                return '我是'+this.name+',今年'+this.age+'岁';
            }
            p2.say();
            console.log(p2.name, p2.age);
            console.log(p2);
        </script>
    </body>
</html>